package com.jzzz.onenotification;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;


public class NotificationService extends Service {

    Handler handler = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1) {
                NotificationBean notificationBean = new NotificationBean("一个通知", "一个通知");
                NotificationUtil.getInstance(NotificationService.this).sendNotification(notificationBean);
                handler.sendEmptyMessageDelayed(1, 1000);
            }
        }
    };

    @Override
    public void onCreate() {
        super.onCreate();
        NotificationUtil.getInstance(this)
                .setPri(NotificationManager.IMPORTANCE_HIGH)
                .setDefaults(Notification.DEFAULT_ALL)
                .startForeground(this);

        handler.sendEmptyMessage(1);
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return Service.START_STICKY;
    }

    @Override
    public void onDestroy() {
        handler.removeCallbacksAndMessages(null);
        super.onDestroy();
    }
}